package com.forestar.xzk.appcommon;

import android.content.Context;

/**
 * @author xzk
 * @data 2020/4/24
 * @email xiezhengkun@beyondsoft.com
 * @remark  上传的资源名称
 */
public class ResourceUtil {

    private static Context context;
    public static void init(Context context){
        ResourceUtil.context=context;
    }

    /**
     * type 表示的是 类型
     * @param iconName
     * @return
     */
    //关键点通过下面方式获取id，drawable资源
    public static int getResIconId(String iconName){
        if(null == ResourceUtil.context){
            return -1;
        }
        return ResourceUtil.context.getResources().getIdentifier(iconName, "drawable", context.getPackageName());
    }
    public static int getResMipmapIconId(String iconName){
        if(null == ResourceUtil.context){
            return -1;
        }
        return context.getResources().getIdentifier(iconName, "mipmap", context.getPackageName());
    }

    //字符串资源
    public static int getResNameId( String iconName){
        if(null == ResourceUtil.context){
            return -1;
        }
        return context.getResources().getIdentifier(iconName, "string", context.getPackageName());
    }

}
